package June;

import java.util.ArrayList;
import java.util.Scanner;

public class Test06ArrayList02 {
    public static void main(String[] args) {
        //创建集合
        ArrayList<Test06ArrayList02Class> list = new ArrayList<>();

        //创建三个用户对象表
        Test06ArrayList02Class stu1 = new Test06ArrayList02Class("王五", 18, '男', "123456");
        Test06ArrayList02Class stu2 = new Test06ArrayList02Class("赵四", 18, '男', "123qwer");
        Test06ArrayList02Class stu3 = new Test06ArrayList02Class("张三", 18, '男', "qwer12345");
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个姓名，我将在集合中查找是否存在");
        String next = sc.next();
//        boolean flag=check(list,next);
//        System.out.println(flag);
        check(list, next);
    }

    public static boolean check(ArrayList<Test06ArrayList02Class> list, String id) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getName().equals(id)) {
                System.out.println("该姓名存在");
                return true;
            }
        }
        System.out.println("不存在");
        return false;
    }
}
